from django.contrib import admin
from question.models import Course, Chapter, Section, KnowledgePoint, Questions, GuidePaper, Subject, ExaminationPaper
from question.models import GeneralPaperApplication, JointPaperApplication, QuestionOnlineApplication, GuidePaperFeedback
from question.models import SwiperImage, Bulletin, Category, Book, PermitExplainPaperOfUser, Video, PermitVideoOfQuestion


class CourseInline(admin.StackedInline):
    model = Course


class ChapterInline(admin.StackedInline):
    model = Chapter


class SectionInline(admin.StackedInline):
    model = Section


class PointInline(admin.StackedInline):
    model = KnowledgePoint


class QuestionsInline(admin.TabularInline):
    model = Questions


class GuidePaperInline(admin.TabularInline):
    model = GuidePaper


@admin.register(Subject)
class SubjectAdmin(admin.ModelAdmin):
    list_display = ['name', 'order']
    inlines = [CourseInline]
    ordering = ('order',)


@admin.register(Course)
class CourseAdmin(admin.ModelAdmin):
    list_display = ['name', 'overview', 'order']
    inlines = [ChapterInline]
    ordering = ('order',)


@admin.register(Chapter)
class ChapterAdmin(admin.ModelAdmin):
    list_display = ['name', 'overview', 'course', 'order']
    list_filter = ['name', 'course']
    search_fields = ['name']
    inlines = [SectionInline]
    ordering = ('course', 'order')


@admin.register(Section)
class SectionAdmin(admin.ModelAdmin):
    list_display = ['name','overview','chapter','order']
    list_filter = ['name', 'chapter']
    search_fields = ['name']
    inlines = [PointInline]
    ordering = ('chapter', 'order')


@admin.register(KnowledgePoint)
class KnowledgePointAdmin(admin.ModelAdmin):
    list_display = ['name', 'overview', 'section', 'order']
    list_filter = ['name', 'section']
    search_fields = ['name']
    inlines = [GuidePaperInline]
    ordering = ('section', 'order')


@admin.register(Questions)
class QuestionsAdmin(admin.ModelAdmin):
    list_display = ['content', 'owner', 'add_time', 'type']
    list_filter = ['type', 'need_video', 'owner']
    search_fields = ['content']
    ordering = ['order']


@admin.register(GuidePaper)
class GuidePaperAdmin(admin.ModelAdmin):
    list_display = ['title', 'owner', 'add_time']
    list_filter = ['type']
    search_fields = ['title']
    ordering = ['order']


@admin.register(ExaminationPaper)
class ExaminationPaperAdmin(admin.ModelAdmin):
    list_display = ['title', 'publish_time', 'expiration', 'owner', 'description', "online", 'open_level', 'is_joint']
    list_filter = ['is_joint']
    search_fields = ['title']
    ordering = ['publish_time']


@admin.register(GeneralPaperApplication)
class GeneralPaperApplication(admin.ModelAdmin):
    list_display = ['user', 'add_date', 'paper', 'status', "last_edit_time"]
    list_filter = ['status']
    search_fields = ['user']
    ordering = ['add_date']


@admin.register(JointPaperApplication)
class JointPaperApplication(admin.ModelAdmin):
    list_display = ['user', 'add_date', 'paper', 'status', "last_edit_time"]
    list_filter = ['status']
    search_fields = ['user']
    ordering = ['add_date']


@admin.register(QuestionOnlineApplication)
class QuestionOnlineApplication(admin.ModelAdmin):
    list_display = ['user', 'add_date', 'question', 'status', "last_edit_time"]
    list_filter = ['status']
    search_fields = ['user']
    ordering = ['add_date']


@admin.register(GuidePaperFeedback)
class FeedbackGuidePaper(admin.ModelAdmin):
    list_display = ['paper', 'add_time', 'content', 'owner']
    list_filter = ['paper']
    search_fields = ['content']
    ordering = ['add_time']


@admin.register(SwiperImage)
class SwiperImage(admin.ModelAdmin):
    list_display = ['title', 'image_url', 'href_url', 'type', 'top', 'add_time']
    list_filter = ['type']
    search_fields = ['title']
    ordering = ['top', '-add_time']


@admin.register(Bulletin)
class Bulletin(admin.ModelAdmin):
    list_display = ['title', 'content', 'add_time']
    list_filter = ['add_time', 'title']
    search_fields = ['title']
    ordering = ['-add_time']


@admin.register(Category)
class Category(admin.ModelAdmin):
    list_display = ['name', 'icon']
    list_filter = ['name']
    search_fields = ['name']
    ordering = ['name']


@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
    list_display = ['name', 'remark', 'cover', 'author', 'publish_date', 'file']
    list_filter = ['publish_date', 'name']
    search_fields = ['name']
    ordering = ['author', 'name']


@admin.register(PermitExplainPaperOfUser)
class PermitExplainPaperOfUserAdmin(admin.ModelAdmin):
    list_display = ['paper', 'user', 'status', 'add_time']
    list_filter = ['paper', 'user', 'status']
    search_fields = ['paper']
    ordering = ['-add_time', 'status']


@admin.register(Video)
class VideoAdmin(admin.ModelAdmin):
    list_display = ['add_time', 'owner', 'question', 'url']
    list_filter = ['owner', 'add_time']
    search_fields = ['url']
    ordering = ['-add_time', 'owner']


@admin.register(PermitVideoOfQuestion)
class PermitVideoOfQuestionAdmin(admin.ModelAdmin):
    list_display = ['question', 'user', 'status', 'add_time']
    list_filter = ['question', 'user', 'status']
    search_fields = ['question']
    ordering = ['-add_time', 'status']